﻿from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtUiTools import *

class SearchWindow(QObject):
    ui = None

    def __init__(self, parent):
        super(SearchWindow, self).__init__()

        qApp.searchWindow = self

        uifile = QFile("SearchWindow.ui")
        if not uifile.open(QIODevice.ReadOnly):
            sys.exit(1)
        uiloader = QUiLoader()
        self.ui = uiloader.load(uifile, parent)
        if self.ui == None:
            sys.exit(2)
        self.ui.setWindowFlags(Qt.Tool)
        self.ui.installEventFilter(self)
        uifile.close()

        self.tabWidget = self.ui.findChild(QTabWidget, "tabWidget")

    def show(self, tabIndex = 0):
        self.ui.show()
        self.tabWidget.setCurrentIndex(tabIndex)
        cmb = self.ui.findChild(QComboBox, "cmbPage" + str((tabIndex + 1)))
        qApp.setActiveWindow(self.ui)
        self.ui.setFocus()
        cmb.setFocus()

    def findNext(self):
        pass

    def findPrevious(self):
        pass

    def eventFilter(self, obj, event):
        if obj == self.ui and event.type() == QEvent.KeyPress:
            if event.key() == Qt.Key_Escape:
                self.ui.close()
        return False










